const md5 = require("md5");
const jwt = require("jwt-simple");
const moment = require("moment");
const KEY = "#$%^&*()%^&*()P^&*(OP";
module.exports = {
	getMd5(str){
		return md5(str+KEY);
	},
	getNowTime(){
		return moment().format("YYYY-MM-DD HH:mm:ss")
	},
	jwtEncode(payload,s=60*60){
		// 加密
		return jwt.encode({
			...payload,
			exp:Date.now()/1000+s
		},KEY)
	},
	jwtDecode(token){
		// 解密
		return new Promise(resolve=>{
			const payload = jwt.decode(token,KEY)
			resolve(payload);
		})
	}
}